Skip to content

fix: prevent floating compare bar DOM accumulation on repeated toggle(#225)#232

Merged
jagdish-15 merged 1 commit into
codepvg:mainfrom
rishab11250:feature/fix-compare-bar-dom-leak-issue225
Jun 21, 2026
Merged

fix: prevent floating compare bar DOM accumulation on repeated toggle(#225)#232
jagdish-15 merged 1 commit into
codepvg:mainfrom
rishab11250:feature/fix-compare-bar-dom-leak-issue225

Conversation

@rishab11250

Copy link
Copy Markdown
Contributor

Description

Fixes two issues in updateFloatingCompareBar() that caused DOM element accumulation and fragile event listener re-binding on repeated compare mode toggling. The floating compare bar is now fully removed from DOM when no users are selected, and button clicks are handled via event delegation instead of individual addEventListener calls.

Linked Issue

Fixes #225

Changes Made

  • clearSelectedUsers() path: Changed bar.style.display = "none" to bar.remove() — the bar element is now fully removed from DOM when no users are selected instead of just hidden
  • Event delegation: Replaced three individual addEventListener calls on buttons with a single delegated click listener on the bar element, bound only once when the bar is first created. The listener uses e.target.closest("button") to route clicks to the correct handler (clearSelectedUsers, toggleCompareMode, or openCompareModal)
  • When compare mode is re-activated, document.getElementById() returns null (bar was removed), so a fresh bar is created with a single fresh delegated listener — clean slate every time

Type of Change

  • Bug fix
  • New feature
  • UI/Visual update
  • Documentation update
  • Refactor

Testing

  • Tested locally
  • Tested on mobile viewport (if applicable)
  • No console errors introduced
  • Verified with npx prettier --check frontend/js/leaderboard/compare.js

Checklist

  • My code follows the project's coding style
  • I have formatted my code locally by running npx prettier --write . before submitting
  • I am submitting my PR from a dedicated feature/* branch, not the main branch
  • I have performed a self-review of my code
  • My changes generate no new warnings or errors
  • I have updated documentation if required
  • I have linked the relevant issue

Screenshots / Screen Recording

N/A — no visual change, same behavior with cleaner DOM lifecycle.

…codepvg#225)

Remove bar from DOM instead of hiding it when no users are selected. Replace individual addEventListener calls with event delegation on the bar element, binding the listener only once when the bar is first created.
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for submitting a pull request.

Please ensure your changes comply with the project's contribution guidelines and that all workflow checks pass successfully.

Formatting and Branching

  • Please confirm you have formatted your code locally using npx prettier --write ., or you can simply comment /format on this PR to have our bot do it for you!
  • Ensure this PR is made from a feature/* branch and not main.

Note: This project is currently maintained by a solo maintainer, so reviews and responses may sometimes take a little time. Thanks for your patience.

@jagdish-15 jagdish-15 merged commit a096ebd into codepvg:main Jun 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: Floating compare bar DOM elements accumulate on repeated toggle

2 participants